#ifndef UL_DEFINE_H_ 
#define UL_DEFINE_H_
#include <linux/unistd.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
#include <new>
#define SAFE_CLOSE(fd)\
do\
{\
  close(fd);\
  fd = -1;\
} while (0)

#define SAFE_DELETE_PTR(ptr)\
do\
{\
  delete ptr;\
  ptr  = NULL;\
} while (0)

#define SAFE_DELETE_ARR(ptr)\
do\
{\
  delete [] ptr;\
  ptr = NULL;\
} while (0)

/// @def transfer errno to return value
#define ERRNO2ERR(err) (-1*err)

#ifdef _syscall0
static _syscall0(pid_t,gettid)
#else
inline pid_t gettid()
{
  return syscall(__NR_gettid);
}
#endif

#ifndef UNUSED
#define UNUSED(v) ((void)(v))
#endif

#endif /* UL_DEFINE_H_ */
